﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//new
using System.IO;
using System.Xml;

namespace JKZP
{
    public partial class TongJiForm : Form
    {
        public TongJiForm()
        {
            InitializeComponent();
        }

        private void TongJiForm_Load(object sender, EventArgs e)
        {
            try
            {
                DateTime t = DateTime.Now;
                dateTimePicker2.Value = t;
                dateTimePicker1.Value = new DateTime(t.Year, t.Month, 1);

                dataGridView1.Rows.Clear();
                if (PP.gISWebVersion == false)
                {
                    dataGridView1.Rows.Add(new object[] { PP.gUser.username, "" });
                }
                else
                {
                    if ((PP.gUserXml != null) && (PP.gUserXml != ""))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(PP.gUserXml);
                        XmlNodeList nodes = doc.SelectNodes("param/user");
                        if (nodes != null)
                        {
                            foreach (XmlNode node in nodes)
                            {
                                dataGridView1.Rows.Add(new object[] { node.Attributes["username"].Value, "" });
                            }
                        }
                    }
                }
                
            }
            catch { }
        }

        private void button_tongji_Click(object sender, EventArgs e)
        {
            try
            {
                if (dateTimePicker1.Value > dateTimePicker2.Value)
                {
                    this.toolStripStatusLabel1.Text = "开始时间不能超过结束时间";
                    return;
                }

                if (PP.gISWebVersion == false)
                {
                    if (dataGridView1.Rows.Count > 0)
                    {
                        int count = PP.GetGZL(PP.gUser.username, dateTimePicker1.Value.ToString(), dateTimePicker2.Value.ToString());
                        dataGridView1.Rows[0].Cells["gzl"].Value = count.ToString();
                    }
                }
                else
                {
                    if (dataGridView1.Rows.Count > 0)
                    {
                        for (int i = 0; i < dataGridView1.Rows.Count; i++)
                        {
                            string username = dataGridView1.Rows[i].Cells["username"].Value.ToString();
                            int count = PP.kdws.JKZP_GetGZL(username, dateTimePicker1.Value.ToString(), dateTimePicker2.Value.ToString());
                            dataGridView1.Rows[i].Cells["gzl"].Value = count.ToString();
                        }
                    }
                }

                this.toolStripStatusLabel1.Text = "统计完毕";
            }
            catch { }
        }
    }
}
